package com.xt.favorites.admin.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xt.favorites.admin.entity.CollectEntity;
import com.xt.favorites.admin.service.CollectService;
import com.xt.common.utils.PageUtils;
import com.xt.common.utils.R;



/**
 * 
 *
 * @author xt
 * @email xt@gmail.com
 * @date 2023-03-02 21:02:36
 */
@RestController
@RequestMapping("admin/collect")
public class CollectController {
    @Autowired
    private CollectService collectService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("admin:collect:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = collectService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("admin:collect:info")
    public R info(@PathVariable("id") Long id){
		CollectEntity collect = collectService.getById(id);

        return R.ok().put("collect", collect);
    }

    /**
     * 获取收藏地址总量+日注册量
     * @return
     */
    @RequestMapping("/console")
    public R console(){
        List<Map<String,Integer>> data = collectService.console();
        return R.ok().put("data", data);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("admin:collect:save")
    public R save(@RequestBody CollectEntity collect){
		collectService.save(collect);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("admin:collect:update")
    public R update(@RequestBody CollectEntity collect){
		collectService.updateById(collect);

        return R.ok();
    }
    /**
     * 修改
     */
    @RequestMapping("/update-status")
    public R updateStatus(@RequestBody CollectEntity collect){
        collectService.updateById(collect);
        return R.ok();
    }
    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("admin:collect:delete")
    public R delete(@RequestBody Long[] ids){
		collectService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
